<template>
  <el-dialog
    :title="dataForm.urlDesc"
    :close-on-click-modal="true"
    :visible.sync="visible"
    width="50%">
    <el-form ref="dataForm" :model="dataForm" status-icon label-width="80px" @keyup.enter.native="dataFormSubmit()">
      <el-form-item label="入参" >
        <json-editor ref="jsonEditor" v-model="jsonS.inParamter"/>
      </el-form-item>
      <el-form-item label="返回结果" >
        <json-editor ref="jsonEditor" v-model="jsonS.outParamter"/>
      </el-form-item>
      <el-form-item label="异常信息" >
        <el-input v-model="dataForm.exception" :rows="8" type="textarea"/>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { getInfo } from '@/api/optLog' // 模块js引用
import JsonEditor from '@/components/JsonEditor'
export default {
  components: { JsonEditor },
  data() {
    return {
      visible: false,
      dataForm: {
        requestNo: '',
        urlDesc: '',
        inParamter: '',
        outParamter: '',
        exception: ''
      },
      jsonS: {
        inParamter: {},
        outParamter: {}
      }
    }
  },
  methods: {
    init(requestNo, urlDesc) {
      this.dataForm.requestNo = requestNo || ''
      this.dataForm.urlDesc = urlDesc || ''
      this.visible = true
      this.$nextTick(() => {
        if (this.dataForm.requestNo) {
          getInfo(this.dataForm.requestNo)
            .then(({ data }) => {
              if (data) {
                this.jsonS.inParamter = JSON.parse(data.inParamter)
                this.jsonS.outParamter = JSON.parse(data.outParamter)
                this.dataForm.exception = data.exception
              }
            })
        }
      })
    }
  }
}
</script>
